"""
标签管理模型
"""
from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field

class TagBase(BaseModel):
    """标签基础模型"""
    name: str = Field(..., min_length=1, max_length=50, description="标签名称")
    color: Optional[str] = Field("#1890ff", description="标签颜色")
    description: Optional[str] = Field(None, max_length=200, description="标签描述")
    module_type: Optional[str] = Field(None, description="所属模块类型（project/requirement/task/defect/test_case/document等）")
    usage_count: Optional[int] = Field(0, description="使用次数")
    is_system: Optional[bool] = Field(False, description="是否为系统标签")

class TagCreate(TagBase):
    """创建标签模型"""
    pass

class TagUpdate(BaseModel):
    """更新标签模型"""
    name: Optional[str] = Field(None, min_length=1, max_length=50, description="标签名称")
    color: Optional[str] = Field(None, description="标签颜色")
    description: Optional[str] = Field(None, max_length=200, description="标签描述")
    module_type: Optional[str] = Field(None, description="所属模块类型")

class TagResponse(TagBase):
    """标签响应模型"""
    id: str = Field(..., description="标签ID")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")

    class Config:
        from_attributes = True

class TagFilter(BaseModel):
    """标签筛选模型"""
    module_type: Optional[str] = Field(None, description="模块类型筛选")
    search: Optional[str] = Field(None, description="搜索关键词（名称或描述）")
    include_system: Optional[bool] = Field(True, description="是否包含系统标签")